* IN STATA 

* Table One
use "NationalData.dta", replace
drop if year<=1864
reg turnout tminus1turnout

* Figure One
use "NationalData.dta", replace 
drop if year<=1864
reg turnout tminus1turnout
capture drop residuals
predict residuals, residuals
capture drop predict
gen predict=turnout+residuals
twoway (line turnout year, sort lpattern(dash) lcolor(black)) (line predict year, sort lpattern(dot) lcolor(black)), xtitle("Year") ytitle("Turnout") legend(label(1 "Actual") label(2 "Predicted")) xlabel(1864(24)2020)

* Table Two
use "StateData.dta", replace
drop if year==1980
reg turnout tminus1 anysame white college, cluster(state_id)

* Figure Two
use "FigureTwoData.dta", replace
 twoway (line turnout year, sort lpattern(dash) lcolor(black)) (line predict year, sort lpattern(dot) lcolor(black)), xtitle("Year") ytitle("Turnout") legend(label(1 "Actual")  label(2 "Predicted")) xlabel(1984(4)2020)


* Table Three
use "StateData.dta", replace
drop if year==1980
reg turnout tminus1 anysame white college
margins, at(college=28.8 white=69.8 tminus1=61.5 anysame=0)
margins, at(college=30.6 white=72.6 tminus1=65.2 anysame=0)
margins, at(college=33 white=76.5 tminus1=58.4 anysame=0)
margins, at(college=25.4 white=79.3 tminus1=52.3 anysame=0)
margins, at(college=37 white=56.6 tminus1=56.8 anysame=1)
margins, at(college=45.9 white=84.3 tminus1=70.9 anysame=1)
margins, at(college=41.9 white=75.2 tminus1=64.2 anysame=1)
margins, at(college=36.5 white=68.2 tminus1=64.5 anysame=0)
margins, at(college=34.3 white=73.9 tminus1=63.1 anysame=0)
margins, at(college=34.7 white=58.7 tminus1=60.5 anysame=0)
margins, at(college=35.4 white=43.8 tminus1=51.5 anysame=1)
margins, at(college=32.3 white=91.4 tminus1=62.7 anysame=1)
margins, at(college=37.7 white=71.3 tminus1=61.4 anysame=1)
margins, at(college=29.6 white=84.1 tminus1=58.2 anysame=0)
margins, at(college=32.3 white=90.7 tminus1=69.3 anysame=1)
margins, at(college=35.6 white=85.8 tminus1=60 anysame=0)
margins, at(college=27.9 white=88.8 tminus1=61.4 anysame=0)
margins, at(college=27.1 white=63.9 tminus1=58.2 anysame=0)
margins, at(college=36.1 white=96 tminus1=74.2 anysame=1)
margins, at(college=43.8 white=55.4 tminus1=64.2 anysame=1)
margins, at(college=46.6 white=77.8 tminus1=65.2 anysame=0)
margins, at(college=32.1 white=80.7 tminus1=70.4 anysame=1)
margins, at(college=39.1 white=83.5 tminus1=74.8 anysame=1)
margins, at(college=24.8 white=59.8 tminus1=57.6 anysame=0)
margins, at(college=32.2 white=84.6 tminus1=63.1 anysame=0)
margins, at(college=34.6 white=91.7 tminus1=70.9 anysame=1)
margins, at(college=34.7 white=86.8 tminus1=64.7 anysame=0)
margins, at(college=27 white=65.2 tminus1=57.3 anysame=1)
margins, at(college=41.3 white=93.9 tminus1=72.2 anysame=1)
margins, at(college=43.5 white=64.8 tminus1=65.4 anysame=0)
margins, at(college=30.5 white=70.8 tminus1=56.5 anysame=1)
margins, at(college=40 white=63.4 tminus1=55.9 anysame=0)
margins, at(college=35.9 white=69.4 tminus1=66.3 anysame=1)
margins, at(college=31.8 white=88.2 tminus1=61.9 anysame=0)
margins, at(college=32 white=83.1 tminus1=64.8 anysame=0)
margins, at(college=28.5 white=78.6 tminus1=51.5 anysame=0)
margins, at(college=36.3 white=85.8 tminus1=69.7 anysame=0)
margins, at(college=35.1 white=80.9 tminus1=67.9 anysame=0)
margins, at(college=39.6 white=80.1 tminus1=60.4 anysame=0)
margins, at(college=32.6 white=69.5 tminus1=61.1 anysame=0)
margins, at(college=31.6 white=86.7 tminus1=62.6 anysame=0)
margins, at(college=31.1 white=79.5 tminus1=56.6 anysame=0)
margins, at(college=33.9 white=70.6 tminus1=51.3 anysame=0)
margins, at(college=37.9 white=87.7 tminus1=63.5 anysame=1)
margins, at(college=44.2 white=96.2 tminus1=71.8 anysame=1)
margins, at(college=42.2 white=68.6 tminus1=66.3 anysame=0)
margins, at(college=39.5 white=77.7 tminus1=67.3 anysame=1)
margins, at(college=24.8 white=94.9 tminus1=55.9 anysame=0)
margins, at(college=33.2 white=88 tminus1=71.9 anysame=1)
margins, at(college=29.6 white=92.6 tminus1=61.8 anysame=1)


* Supplemental Table Two
use "NationalData.dta", replace
drop if year<=1864
reg turnout tminus1 if year !=2020
margins, at(tminus1=.601)
gen newvar = .601816 if year==2020
reg turnout tminus1 if year !=2016
margins, at(tminus1=.586)
recode newvar (.= .5906025) if year==2016
reg turnout tminus1 if year !=2012
margins, at(tminus1=.616)
recode newvar (.= .6168035) if year==2012
reg turnout tminus1 if year !=2008
margins, at(tminus1=.601)
recode newvar (.= .6030959) if year==2008
reg turnout tminus1 if year !=2004
margins, at(tminus1=.542)
recode newvar (.= .5518205) if year==2004
reg turnout tminus1 if year !=2000
margins, at(tminus1=.517)
recode newvar (.= .5327107) if year==2000
reg turnout tminus1 if year !=1996
margins, at(tminus1=.581)
recode newvar (.= .5891138) if year==1996
reg turnout tminus1 if year !=1992
margins, at(tminus1=.528)
recode newvar (.= .5402233) if year==1992
reg turnout tminus1 if year !=1988
margins, at(tminus1=.528)
recode newvar (.= .54422) if year==1988
reg turnout tminus1 if year !=1984
margins, at(tminus1=.542)
recode newvar (.= .5542793) if year==1984
reg turnout tminus1 if year !=1980
margins, at(tminus1=.548)
recode newvar (.= .5599912) if year==1980
reg turnout tminus1 if year !=1976
margins, at(tminus1=.562)
recode newvar (.= .5718083) if year==1976
reg turnout tminus1 if year !=1972
margins, at(tminus1=.625)
recode newvar (.= .6251384) if year==1972
reg turnout tminus1 if year !=1968
margins, at(tminus1=.628)
recode newvar (.= .6260441) if year==1968
reg turnout tminus1 if year !=1964
margins, at(tminus1=.638)
recode newvar (.= .6345399) if year==1964
reg turnout tminus1 if year !=1960
margins, at(tminus1=.602)
recode newvar (.= .6033216) if year==1960
reg turnout tminus1 if year !=1956
margins, at(tminus1=.623)
recode newvar (.= .6223669) if year==1956
reg turnout tminus1 if year !=1952
margins, at(tminus1=.522)
recode newvar (.= .5321262) if year==1952
reg turnout tminus1 if year !=1948
margins, at(tminus1=.559)
recode newvar (.= .5703153) if year==1948
reg turnout tminus1 if year !=1944
margins, at(tminus1=.624)
recode newvar (.= .624363) if year==1944
reg turnout tminus1 if year !=1940
margins, at(tminus1=.61)
recode newvar (.= .6106187) if year==1940
reg turnout tminus1 if year !=1936
margins, at(tminus1=.569)
recode newvar (.= .5754669) if year==1936
reg turnout tminus1 if year !=1932
margins, at(tminus1=.569)
recode newvar (.= .5770196) if year==1932
reg turnout tminus1 if year !=1928
margins, at(tminus1=.489)
recode newvar (.= .5046455) if year==1928
reg turnout tminus1 if year !=1924
margins, at(tminus1=.492)
recode newvar (.= .5144119) if year==1924
reg turnout tminus1 if year !=1920
margins, at(tminus1=.618)
recode newvar (.= .6210408) if year==1920
reg turnout tminus1 if year !=1916
margins, at(tminus1=.59)
recode newvar (.= .5935254) if year==1916
reg turnout tminus1 if year !=1912
margins, at(tminus1=.657)
recode newvar (.= .6519387) if year==1912
reg turnout tminus1 if year !=1908
margins, at(tminus1=.655)
recode newvar (.= .6483392) if year==1908
reg turnout tminus1 if year !=1904
margins, at(tminus1=.737)
recode newvar (.= .7207461) if year==1904
reg turnout tminus1 if year !=1900
margins, at(tminus1=.796)
recode newvar (.= .769602) if year==1900
reg turnout tminus1 if year !=1896
margins, at(tminus1=.758)
recode newvar (.= .7300716) if year==1896
reg turnout tminus1 if year !=1892
margins, at(tminus1=.805)
recode newvar (.= .7758008) if year==1892
reg turnout tminus1 if year !=1888
margins, at(tminus1=.782)
recode newvar (.= .7498692) if year==1888
reg turnout tminus1 if year !=1884
margins, at(tminus1=.805)
recode newvar (.= .7729117) if year==1884
reg turnout tminus1 if year !=1880
margins, at(tminus1=.826)
recode newvar (.= .7894314) if year==1880
reg turnout tminus1 if year !=1876
margins, at(tminus1=.721)
recode newvar (.= .6976419) if year==1876
reg turnout tminus1 if year !=1872
margins, at(tminus1=.809)
recode newvar (.= .7842702) if year==1872
reg turnout tminus1 if year !=1868
margins, at(tminus1=.763)
recode newvar  (.=.733309) if year==1868
* next line shows the difference between the predicted turnout and the actual turnout
gen diffvar = abs(newvar-turnout)
* next line shows the average difference per election between predicted and actual turnout
* this value is in the last row of the table
sum diffvar
* this sets up the display of the the data
rename newvar preturnout
order year newvar turnout diffvar
drop tminus
browse
* the table should now be displayed 


* Supplemental Table Two
use "StateData.dta", replace
drop if year==1980
reg turnout tminus1 anysame white college if year != 2020
capture drop predicted_turnout
predict predicted_turnout20 if year==2020, xb
recode predicted_turnout20 (.=0)
reg turnout tminus1 anysame white college if year != 2016
predict predicted_turnout16 if year==2016, xb
recode predicted_turnout16 (.=0)
reg turnout tminus1 anysame white college if year != 2012
predict predicted_turnout12 if year==2012, xb
recode predicted_turnout12 (.=0)
reg turnout tminus1 anysame white college if year != 2008
predict predicted_turnout08 if year==2008, xb
recode predicted_turnout08 (.=0)
reg turnout tminus1 anysame white college if year != 2004
predict predicted_turnout04 if year==2004, xb
recode predicted_turnout04 (.=0)
reg turnout tminus1 anysame white college if year != 2000
predict predicted_turnout00 if year==2000, xb
recode predicted_turnout00 (.=0)
reg turnout tminus1 anysame white college if year != 1996
predict predicted_turnout96 if year==1996, xb
recode predicted_turnout96 (.=0)
reg turnout tminus1 anysame white college if year != 1992
predict predicted_turnout92 if year==1992, xb
recode predicted_turnout92 (.=0)
reg turnout tminus1 anysame white college if year != 1988
predict predicted_turnout88 if year==1988, xb
recode predicted_turnout88 (.=0)
reg turnout tminus1 anysame white college if year != 1984
predict predicted_turnout84 if year==1984, xb
recode predicted_turnout84 (.=0)
* next line shows the predicted turnout for every state
gen totalpredict = predicted_turnout20+ predicted_turnout16+predicted_turnout12+predicted_turnout08+predicted_turnout04+predicted_turnout00+predicted_turnout96+predicted_turnout92+predicted_turnout88+predicted_turnout84
* next line shows the difference between the predicted turnout and the actual turnout
gen diffvar = abs(totalpredict-turnout)
* next line shows the average difference per state between predicted and actual turnout
* this will display the last line of the table
sum diffvar
keep year state totalpredict turnout diffvar
browse
* the table should now be displayed


